package com.travelgroup.controller;

import com.travelgroup.domain.dto.ScheduleDTO;
import com.travelgroup.domain.dto.TourGroupDTO;
import com.travelgroup.domain.vo.ScheduleVO;
import com.travelgroup.domain.vo.TourGroupVO;
import com.travelgroup.exception.R;
import com.travelgroup.service.IScheduleService;
import com.travelgroup.service.ITourGroupService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/tour-group")
@Tag(name = "拼团模块")
public class TourGroupController {
    @Resource
    private ITourGroupService tourGroupService;
    @Resource
    private IScheduleService scheduleService;

    @Operation(summary = "发布拼团")
    @PostMapping("/submit")
    public R<Long> submitTourGroup(@RequestBody TourGroupDTO tourGroup) {
        return tourGroupService.submitTourGroup(tourGroup);
    }

    @Operation(summary = "获取拼团信息")
    @GetMapping("/query/{id}")
    public R<TourGroupVO> queryTourGroupById(@PathVariable Long id) {
        return tourGroupService.queryTourGroupById(id);
    }

    @Operation(summary = "取消拼团")
    @PutMapping("/cancel/{id}")
    public R<Long> cancelTourGroup(@PathVariable Long id) {
        return tourGroupService.cancelTourGroup(id);
    }

    @Operation(summary = "删除拼团信息")
    @DeleteMapping("/delete/{id}")
    public R<?> deleteTourGroup(@PathVariable Long id) {
        return tourGroupService.deleteTourGroup(id);
    }

    @Operation(summary = "修改拼团信息")
    @PutMapping("/update/{id}")
    public R<TourGroupDTO> updateTourGroup(@PathVariable Long id, @RequestBody TourGroupDTO tourGroup) {
        return tourGroupService.updateTourGroupById(id, tourGroup);
    }

    @Operation(summary = "修改行程信息")
    @PutMapping("/update/schedule/{id}")
    public R<ScheduleDTO> updateSchedule(@PathVariable Long id, @RequestBody ScheduleDTO schedule) {
        return scheduleService.updateSchedule(id, schedule);
    }

    @Operation(summary = "查询行程信息")
    @GetMapping("/query/schedule/{id}")
    public R<List<ScheduleVO>> queryScheduleByIds(@PathVariable Long id) {
        return scheduleService.queryScheduleByIds(id);
    }

    @Operation(summary = "根据id删除行程信息")
    @GetMapping("/delete/schedule/{itineraryId}/{id}")
    public R<?> deleteScheduleById(@PathVariable Long itineraryId, @PathVariable Long id) {
        return scheduleService.deleteScheduleById(itineraryId, id);
    }

}
